﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolERP_Entities;
using CoolERP_BLL;
using System.Text;
using System.Web.UI.HtmlControls;

namespace CoolERP_Web.User
{
    public partial class CPBZX_Query : BasePage
    {
        protected string cpxbh
        {
            get { return this.GetUrlParam("cpxbh").ToString(); }
        }
        protected string hxcbh
        {
            get { return this.GetUrlParam("hxcbh").ToString(); }
        }
        protected Guid id
        {
            get { return this.GetUrlParam("cpid") == null ? Guid.Empty : new Guid(this.GetUrlParam("cpid").ToString()); }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnAdd.PostBackUrl = string.Format("CPBZX_Edit.aspx?cpid={0}&cpxbh={1}&hxcbh={2}", id, cpxbh, hxcbh);
                BindData();
            }
        }

        private void BindData()
        {
            using (ZL_CPBZXBLL cBLL = new ZL_CPBZXBLL())
            {
                List<ZL_CPBZX> list = cBLL.GetList(c => c.CPXBH == cpxbh && c.CPMCBH == hxcbh && c.CPID == id);
                this.GridView1.DataSource = list;
                this.GridView1.DataBind();
            }
        }

        protected void btnDel_Click(object sender, ImageClickEventArgs e)
        {
            StringBuilder sbIds = new StringBuilder();
            foreach (GridViewRow container in GridView1.Rows)
            {
                HtmlInputCheckBox cBox = (HtmlInputCheckBox)container.FindControl("chkSel");
                if (cBox != null && cBox.Checked)
                    sbIds.Append(string.Format(",{0}", cBox.Value));
            }
            if (sbIds.Length > 0)
            {
                sbIds = sbIds.Remove(0, 1);
                using (ZL_CPBZXBLL zBLL = new ZL_CPBZXBLL())
                {
                    if (zBLL.Deletes("ID", sbIds.ToString()))
                        this.ShowMessage("删除成功");
                    else
                        this.ShowMessage("删除失败");
                }
                BindData();
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }
    }
}